package com.hang.gymmanager.controller;


import com.hang.gymmanager.common.Response;
import com.hang.gymmanager.req.LoginReq;
import com.hang.gymmanager.req.UserRegisterReq;
import com.hang.gymmanager.service.LoginService;
import com.hang.gymmanager.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 用户控制器
 * @author wyq
 * @version v1.0.0
 * @explain
 * @date 2024/3/20 19:28
 */
@RestController
@RequestMapping("/user")
@Slf4j
@RequiredArgsConstructor
@CrossOrigin
public class UserController {

    private final UserService userService;
    private final LoginService loginService;

    /**
     * 用户注册
     * @param req
     * @return
     */
    @PostMapping("/register")
    public Response userRegister(@RequestBody UserRegisterReq req){
        userService.userRegister(req);
        return Response.success();
    }

    /**
     * 登录并返回token
     * @param req
     * @return
     */
    @PostMapping("/login")
    public Response<String> login(@RequestBody LoginReq req){
        String token = loginService.login(req);
        return Response.success(token);
    }

}
